<template>
  <div class="detail-container app-container" v-loading="listLoading">
    <div class="title-info">
        <div>订单信息</div>
        <el-button type="primary" size="small" @click="handlePrintOrder">订单打印</el-button>
    </div>
    <div class="content-info">
      <el-row :gutter="20">
        <el-col :span="6">订单编号: {{ orderDetails.id_public_goods_order_record }}</el-col>
        <el-col :span="6">送货方式: {{ orderDetails.type_of_shipment === 1 ? '到店自取' : '送货到家' }}</el-col>
        <el-col :span="6">订单状态: {{ orderState[orderDetails.ship_state] }}</el-col>
        <el-col :span="6">下单时间: {{ orderDetails.time_order }}</el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">订单总价: {{ Number(orderDetails.all_price_4_shop_retail).toFixed(2) }}</el-col>
        <el-col :span="6">支付金额: {{ Number(orderDetails.ways_of_payment).toString().charAt(0) === '4' ? '微信支付(' + (Number(orderDetails.pay_by_online).toFixed(2)) + ')' : (Number(orderDetails.ways_of_payment).toString().charAt(0) === '3' ? '支付宝支付(' + (Number(orderDetails.pay_by_online).toFixed(2)) + ')' : '线下支付(' + (Number(orderDetails.pay_by_online).toFixed(2)) + ')') }}</el-col>
        <el-col :span="6">运费: {{ Number(orderDetails.ship_money).toFixed(2) }}</el-col>
        <el-col :span="6">消费门店: {{ public_agent_info.agent_name }}</el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">要求时间: {{ orderDetails.time_require || '-' }}</el-col>
        <el-col :span="6">订单备注: {{ orderDetails.order_remark || '-' }}</el-col>
      </el-row>
    </div>
    <div class="title-info">收件人信息</div>
    <div class="content-info">
      <el-row :gutter="20">
        <el-col :span="6">用户ID: {{ orderDetails.buyer_id }}</el-col>
        <el-col :span="6">下单人名称: {{ orderDetails.receive_name }}</el-col>
        <el-col :span="6">客户电话: {{ orderDetails.phone_user }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="12">客户地址: {{ orderDetails.receive_place }}</el-col>
      </el-row>
    </div>
    <div class="title-info">商品信息</div>
    <div class="content-info">
      <el-table
        :data="orderGoods"
        border
        fit
        highlight-current-row
        style="width: 100%;"
      >
        <el-table-column label="ID" prop="id" align="center" width="80" :class-name="getSortClass('id')">
          <template slot-scope="{row}">
            <span>{{ row.id_public_goods_info }}</span>
          </template>
        </el-table-column>
        <el-table-column label="商品名称" align="center">
          <template slot-scope="{row}">
            <span>{{ row.goods_name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="一级/二级分类" align="center">
          <template slot-scope="{row}">
            <span>{{ row.type_name }} / {{ row.child_name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="零售规格" align="center">
          <template slot-scope="{row}">
            <span>{{ row.sales_describe || '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="出货方式" align="center">
          <template slot-scope="{row}">
            <span>{{ row.type_goods_from === 1 ? '门店出货' : (row.type_goods_from === 2 ? '供应商出货' : '盘点') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="源价/供价/零售价" align="center">
          <template slot-scope="{row}">
            <span>{{ row.price_4_supply_buy }}/{{ row.price_4_shop_buy }}/{{ row.price_4_shop_retail }}</span>
          </template>
        </el-table-column>
        <el-table-column label="数量" align="center" class-name="small-padding fixed-width">
          <template slot-scope="{row}">
            <span>{{ row.order_number }}</span>
          </template>
        </el-table-column>
        <el-table-column label="单价" align="center" class-name="small-padding fixed-width">
          <template slot-scope="{row}">
            <span>{{ row.price_4_shop_retail }}</span>
          </template>
        </el-table-column>
        <el-table-column label="合计" align="center" class-name="small-padding fixed-width">
          <template slot-scope="{row}">
            <span>{{ row.price_4_shop_retail * row.order_number }}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { orderDetail } from '@/api/order';

export default {
  name: 'Details',
  data() {
    return {
      listLoading: true,
      orderDetails: {},
      public_agent_info: {},
      orderGoods: [],
      detailQuery: {
        invoke_method: 'details_4_order',
        id_public_goods_order_record: null
      },
      orderState: {
        0: '已发货',
        1: '已支付',
        3: '配货中',
        4: '已签收',
        5: '已取消',
        8: '支付失败',
        9: '退货中',
        10: '已退款'
      }
    }
  },
  mounted() {
    this.getDetails()
  },
  methods: {
    getDetails() {
      this.detailQuery.id_public_goods_order_record = this.$route.query.order_id
      orderDetail(this.Qs.stringify(this.detailQuery)).then(response => {
        this.orderGoods = response.public_goods_order_detail_list
        this.orderDetails = response.public_goods_order_record
        this.public_agent_info = response.public_agent_info
        setTimeout(() => {
          this.listLoading = false
        }, 0.5 * 1000)
      })
    },

    handlePrintOrder() {
      this.$router.push({name: 'OrderPrint', query: {order_id: this.$route.query.order_id}})
    },

    /*
    * 表格样式
    * */
    getSortClass(key) {
      const sort = this.detailQuery.sort
      return sort === `+${key}` ? 'ascending' : 'descending'
    }
  }
}
</script>

<style lang="scss" scoped>
.title-info {
  padding: 10px 24px;
  color: #222222;
  border-bottom: 2px solid #409EFF;
  font-size: 16px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.content-info {
  padding: 24px 36px;
  .el-row {
    margin-bottom: 26px;
    font-size: 14px;
    &:last-child {
      margin-bottom: 0;
    }
  }
}
</style>
